<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文字水平居中</title>
</head>
<style>
    *{
        margin:0 auto;
    }
    html,body{
        width:100%;
        height:100%;
    }
    .box{
        width:300px;
        height:300px;
        background:crimson;
        display: table-cell;
        text-align: center;
        vertical-align: middle;
    }
</style>
<body>
    
        <div class="box">我是一个居中的元素</div>
</body>
</html>